package com.woniuxy.stage3demo.controller.lyl;


import com.github.pagehelper.PageInfo;
import com.woniuxy.stage3demo.bean.ResultMsg;
import com.woniuxy.stage3demo.bean.chenyuxuanBean.StaffBean;
import com.woniuxy.stage3demo.bean.lyl.MailMessageBean;
import com.woniuxy.stage3demo.bean.lyl.StationMessageBean;
import com.woniuxy.stage3demo.pageHelper.PageRequest;
import com.woniuxy.stage3demo.pageHelper.TableResult;
import com.woniuxy.stage3demo.service.lyl.IMailMsgService;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RequestMapping("/emailmessage")
@RestController
public class EmailMessageController {

    @Resource
    private IMailMsgService mailMsgServiceImpl;
    @RequestMapping(value = "/page",produces = {"application/json;charset=utf-8"})
    public TableResult<MailMessageBean> findAllByParams(PageRequest request, MailMessageBean mailMessageBean, String name){
        System.out.println(mailMsgServiceImpl);

        if(name!=null && name!=""&& mailMessageBean!=null){
            System.out.println(name);
            StaffBean staffBean=new StaffBean();
            staffBean.setName(name);
            mailMessageBean.setStaffBean(staffBean);}
        else if(name!=null && name!=""&& mailMessageBean==null) {
            mailMessageBean = new MailMessageBean();
            StaffBean staffBean=new StaffBean();
            staffBean.setName(name);
            mailMessageBean.setStaffBean(staffBean);
        }
        PageInfo<MailMessageBean> pageInfo = mailMsgServiceImpl.findAllByParams(request,mailMessageBean);
        System.out.println(pageInfo.getList());
        return new TableResult<>(pageInfo.getTotal(),pageInfo.getList());
    }

    @PutMapping(value = "/del/{id}",produces = {"application/json;charset=utf-8"})
    public ResultMsg deleteSysMessageBean(@PathVariable("id") Long id){
        ResultMsg res = new ResultMsg(200,"操作成功",null);
        if(id != null ) {

            mailMsgServiceImpl.deleteOneMailMessageBean(id);
            return res;
        }else{
            res.setCode(10000);
            res.setMsg("更改失败");
            return res;
        }
    }

}
